<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<html>
<head>
	<title>${titile}</title>
	<%@ include file="/WEB-INF/views/mis/common_inc.jsp"%>
	<style>
</style>
</head>

<body style="width:100%;height:100%;overflow-x:hidden;">
	<form class="layui-form layui-form-pane" action="" style="width:80%;margin:0 auto;margin-top: 2%;">
#foreach( $field in $fieldList )
#if( $field.isPk != "Y"&&${field.inputType}!="none"&&${field.inputType}=="hidden")
            <input type="hidden"  name="${field.field}" id="${field.field}"  value="${${model.modelL}.${field.field}}"/>
#end
#if( $field.isPk != "Y"&&${field.inputType}!="hidden"&&${field.inputType}!="none")
                    <div class="layui-form-item #if(${field.inputType}=="textarea"||${field.inputType}=="htmleditor"||${field.inputType}=="file")layui-form-text#end">
                        <label class="layui-form-label">#if(!$field.nullable)#end${field.comment}</label>
                         <div class="layui-input-block">
#if(${field.inputType}=="input")
                        <input type="text" id="${field.field}"  name="${field.field}" placeholder="请输入${field.comment}" #if($field.validate=="mobile")lay-verify="phone"#elseif($field.validate=="email")lay-verify="email"#elseif($field.validate=="url")lay-verify="url"#elseif($field.validate=="identity")lay-verify="identity"#elseif(!$field.nullable)lay-verify="required"#end  value="${${model.modelL}.${field.field}}" class="layui-input" />
#elseif(${field.inputType}=="textarea")
                        <textarea class="layui-textarea"  style="height:100px;width:100%;padding:5px;overflow:auto" id="${field.field}" name="${field.field}"  placeholder="请输入${field.comment}" #if(!$field.nullable)lay-verify="required"#end>${${model.modelL}.${field.field}}</textarea>
#elseif(${field.inputType}=="htmleditor")
                        <textarea class="layui-textarea"  style="height:100px;width:100%;padding:5px;overflow:auto" name="${field.field}" id="${field.field}"  placeholder="请输入${field.comment}" #if(!$field.nullable)lay-verify="required"#end>${${model.modelL}.${field.field}}</textarea>
#elseif(${field.inputType}=="checkbox")
                        <input class="layui-input"  type="checkbox"  name="${field.field}" id="${field.field}" placeholder="请输入${field.comment}" #if(!$field.nullable)lay-verify="required"#end value="${${model.modelL}.${field.field}}"/>
#elseif(${field.inputType}=="radio")
                        <input class="layui-input"  type="radio"  name="${field.field}"  id="${field.field}" placeholder="请输入${field.comment}" #if(!$field.nullable)lay-verify="required"#end  value="${${model.modelL}.${field.field}}"/>
#elseif(${field.inputType}=="datetime")
                        <input id="${field.field}" name="${field.field}" placeholder="请选择时间" autocomplete="off" #if(!$field.nullable)lay-verify="required"#end class="layui-input" type="text" value='<fmt:formatDate value="${${model.modelL}.${field.field}}" pattern="yyyy-MM-dd HH:mm:ss" />'>
#elseif(${field.inputType}=="date")
						<input id="${field.field}" name="${field.field}" placeholder="请选择日期" autocomplete="off" #if(!$field.nullable)lay-verify="required"#end class="layui-input" type="text" value='<fmt:formatDate value="${${model.modelL}.${field.field}}" pattern="yyyy-MM-dd" />'>
#elseif(${field.inputType}=="file")
                        <input   type="hidden"  name="${field.field}" id="${field.field}" value="${${model.modelL}.${field.field}}"/>
						<div class="layui-upload-drag" id="${field.field}_upload" style="width:200px;">
                        <c:if test='${${model.modelL}.${field.field}==null}'>
                           <i class="layui-icon"></i>
                            <p>点击上传，或将图片拖拽到此处</p>
                        </c:if>
                        <c:if test='${${model.modelL}.${field.field}!=null}'>
                           <img src="${${model.modelL}.${field.field}}" style="width:200px;">
                        </c:if>
                   </div>
#elseif(${field.inputType}=="select")
#if("$!field.inputValueOne" == "")
                        <select lay-filter="${field.field}" id="${field.field}" name="${field.field}" style="display: none;" #if(!$field.nullable)lay-verify="required"#end  lay-search="">
							<option value="">==请选择${field.comment}==</option>
							<my:outOptions code="${field.inputValue}" value="${${model.modelL}.${field.field}}"/>
						</select>					
#else
						<select lay-filter="${field.field}_filter" id="${field.field}" name="${field.field}" style="display: none;" #if(!$field.nullable)lay-verify="required"#end lay-search="">
							<option value="">==请选择${field.comment}==</option>
							<c:forEach items="${${field.inputValueOneL}EntityList}" var="item">
							<option value="${ item.code}" <c:if test="${ item.code==${model.modelL}.${field.field}}">selected = "selected"</c:if>>${ item.${field.inputValueTwo}}</option>
							</c:forEach>
						</select>
#end
#end
                        </div>
                   </div>
#end
#end
		 
		  <div class="layui-form-item">
    <div class="layui-input-block">
    
      <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
	</form>
	

<script type="text/javascript">
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引 
//监听键盘事件
document.onkeydown=function(event){
  var e = event || window.event || arguments.callee.caller.arguments[0];
  if(e && e.keyCode==27){ // 按 Esc 
 	 parent.layer.close(index);
    }
   
}; 
layui.use(['form', 'layedit', 'laydate','upload'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,upload =layui.upload;
  layedit.set({//编辑器图片上传接口
	  uploadImage: {
		  url:'${path}/uplodeImg/UEupload'
		 ,type:'post'
	  }
	  });
	  
	  
#foreach( $field in $fieldList )	
#if(${field.inputType}=="htmleditor")
  //${field.comment}使用富文本
  var ${field.field}_index1 = layedit.build('${field.field}');
#elseif(${field.inputType}=="date")
  laydate.render({
    elem: '#${field.field}'
  });
  #elseif(${field.inputType}=="datetime")
  laydate.render({
    elem: '#${field.field}'
	 ,type: 'datetime'
  });
#elseif(${field.inputType}=="file")
    upload.render({elem:'#${field.field}_upload'
	  ,url:'${path}/uplodeImg/upload'
	  ,data: {id:'img'}
	  ,size: 500 //最大允许上传的文件大小
	  ,done:function(res){console.log(res);
	  var imgurl=window.location.protocol+"//"+window.location.host+"/resource/"+res.obj.savePath;
	     $("#${field.field}_upload").html("");
	     $("#${field.field}_upload").html("<img src='"+imgurl+"' style='width:200px;'>");
	     $("#${field.field}").val(imgurl);
	  }
	  });
#end
#end
  //自定义验证规则
  form.verify({
    number: function(value){
      var g = /^[1-9]*[1-9][0-9]*$/;
      if(g.test(value)==false){
        return '请输入正确的正整数';
      }
    }
  });
  //监听提交
  form.on('submit(demo1)', function(data){
#foreach( $field in $fieldList )	
#if(${field.inputType}=="htmleditor")
	  data.field.${field.field}=layedit.getContent(${field.field}_index1);
#end
#end 
	   $.post("${path}/${model.modelL}/saveAdd",data.field,function(d){
  		d=$.parseJSON(d);
  		if(d.returnCode=="SUCCESS"){
  			 layer.msg(d.message);
          	//如果成功关闭弹窗并刷新父页面列表
			    parent.$('#search_button').click();
			    parent.layer.close(index);
          }else{
          	//如果失败弹出提示
			    layer.msg(d.message);
          }
  	}); 
	return false;
  });
  
  //监听下拉
	//form.on('select(filter_name)', function(data) {
	 
		 
//	});
   
});
	
</script>
</body>
</html>